<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>商城首页</title>
  		<jsp:include page="../common/header.jsp"/>
    	<jsp:include page="../../common/validform.jsp"/>
    	<jsp:include page="../common/top.jsp"/>
    		<style type="text/css">
		.btn-address{
	    width: 120px;
	    height: 30px;
	    background-color: #4bbb2f;
	    display: block;
	    line-height: 30px;
	    text-align: center;
	    color: #fff;
		}
	</style>
    <script type="text/javascript" src="${pathUrl}/public/js/PCASClass.js"></script>
    <script type="text/javascript">
      window.onload=function(){
          //初始化省市区
          var mypcas = new PCAS("province,所属省份","city,所属城市","area,所属地区");
      }
    </script>
</head>
<body>

<form action="${pathUrl}/home/cart/submitOrder" method="post" id="mainForm">
<div class="section">
    <div class="cart-head">
        <h2>填写订单</h2>
        <div class="cart-setp">
            <ul>
                <li class="first active">
                    <div class="progress">
                        <span>1</span>
                        放进购物车
                    </div>
                </li>
                <li class="active">
                    <div class="progress ">
                        <span>2</span>
                        填写订单信息
                    </div>
                </li>
                <li class="last">
                    <div class="progress">
                        <span>3</span>
                        支付/确认订单
                    </div>
                </li>
            </ul>
        </div>
    </div>

</div>

<div class="section">
   <div class="cart-box">
       <h2 class="slide-tit">
           <span>1、收货地址</span>
       </h2>
   </div>
	<ul id="userAddress" class="address-list">
	<a href="${pathUrl}/home/cart/addAddress" class="btn-address">新增收货地址</a>
	<c:forEach items="${addresses}" var="ads"> 
             <li>
	             <label>
	                 <input name="user_book_id" type="radio" value="${ads.id}" >
	                 <span>${ads.province},${ads.city},${ads.area}${ads.address}(${ads.userName}收)</span>
	                  <span>手机号码：</span><em>${ads.phone}</em> 
	             </label>
             </li>
             </c:forEach>
          </ul>
    <h2 class="slide-tit">
        <span>2、商品清单</span>
    </h2>
 
   <div class="section">
    <table width="100%" align="center" class="cart-table" border="0" cellspacing="0" cellpadding="8">
        <tbody>
        <tr>
            <th align="left" colspan="2">商品信息</th>
            <th width="84" align="left">单价</th>
            <th width="104" align="center">数量</th>
            <th width="104" align="left">金额(元)</th>
        </tr>
 <c:forEach items="${cartList}" var="bean">
        <tr>
            <td width="68">
                <a target="_blank" href="${pathUrl}home/goods?action=detail&id=${bean.id}">
                    <img onerror="this.src='${pathUrl }/public/images/nopic.png'"  src="${pathUrl}${bean.goods.goodsImg}" class="img">
                </a>
            </td>
            <td>
                <a target="_blank" href="${pathUrl}home/goods?action=detail&id=${bean.id}${bean.goods.goodsName}"></a>
                <p class="stxt"></p>
            </td>
            <td>
                ￥${bean.goods.sellPrice}
            </td>
            <td align="center">
                <div class="buy-box">
                 ${bean.goNum}
                </div>
            </td>
            <td>
                <span class="red">
                    ￥<label name="amountCount">${bean.goods.sellPrice*bean.goNum}</label>
                </span>
            </td>
        </tr>
         <tr>
            <th align="right" colspan="6">
                已选择商品 <b class="red" id="totalQuantity">${bean.goNum}</b> 件 &nbsp;&nbsp;&nbsp;
                商品总金额（不含运费）：<span class="red">￥</span><b class="red" id="totalAmount">${bean.goods.sellPrice*bean.goNum}</b>元
            </th>
        </tr>
         </c:forEach>
         <c:if test="${empty cartList}">
         <tr>
          <td colspan="4">暂无商品</td>
         </tr>
         </c:if>
        </tbody>
    </table>
</div>
 <c:if test="${!empty cartList}">
<div class="cart-foot section">
    <div class="right-box">
    <input id="totalMoney"   type="hidden" value=" ${go_num*goods.marketPrice}"  name="totalMoney"/>
        <button class="button" type="button" onclick="javascript:window.location.href='${pathUrl}/home/goods/index'">继续购物</button>
        <button id="btn_sub" class="submit" >立即结算</button>
    </div>
</div>
</c:if>
</div>
</form>
<script type="text/javascript">
$("#mainForm").Validform({
	btnSubmit:"#btn_sub", 
	btnReset:".btn_reset",
	tiptype:3, 
	ajaxPost:true,
	beforeSubmit:function(data){
		var addressList=$("#userAddress input:checked");
		if(addressList.length<1){
			alert("请新增一个收货地址！");
			return false;
		}
		return true;
	},
	callback:function(data){
		if(data.status==1){
			window.location.href="${pathUrl}/home/cart/pay";
		}else{
			alert(data.msg);
		}
	}
});
$(function(){
	$("input[name='user_book_id']").eq(0).prop("checked",true);
});
</script>
</body>
</html>